package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.FileUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityCollectPicDetailBinding;
import flc.ast.utils.AppSpUtils;
import flc.ast.utils.Content;
import stark.common.basic.utils.FileUtil;
import stark.common.basic.utils.IntentUtil;

public class CollectPicDetailActivity extends BaseAc<ActivityCollectPicDetailBinding> {

    public static String imgPath;

    @Override
    protected int onCreate() {
        return R.layout.activity_collect_pic_detail;
    }

    @Override
    protected void initView() {
        mDataBinding.ivCollectPicDetailBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.ivPicDetailCollect.setOnClickListener(this);
        mDataBinding.tvPicDetailCollect.setOnClickListener(this);
        mDataBinding.tvPicDetailShare.setOnClickListener(this);
        mDataBinding.tvPicDetailPrivacy.setOnClickListener(this);
        mDataBinding.tvPicDetailDelete.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()) {
            case R.id.tvPicDetailDelete:
            case R.id.ivPicDetailCollect:
            case R.id.tvPicDetailCollect://收藏
                List<String> listSp = AppSpUtils.getPicCollectList();
                listSp.remove(imgPath);
                AppSpUtils.savePicCollectList(listSp);
                ToastUtils.showShort(getString(R.string.cancel_collect_suc));
                finish();
                break;
            case R.id.tvPicDetailShare://分享
                IntentUtil.shareImage(mContext, "", imgPath);
                break;
            case R.id.tvPicDetailPrivacy://加入加密
                String filePath = FileUtil.generateFilePath(Content.myPrivacyFile, "." + FileUtils.getFileExtension(imgPath));
                FileUtils.copy(imgPath, filePath);
                ToastUtils.showShort(getString(R.string.add_suc));
                break;
        }
    }

    @Override
    protected void initData() {
        Glide.with(mContext).load(imgPath).into(mDataBinding.ivPicDetailImg);
    }
}